<template>
  <div>
    <!--1视图-->
      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column
            fixed
            prop="id"
            label="用户ID"
            width="50">
        </el-table-column>
        <el-table-column
            prop="uname"
            label="用户名"
            width="150">
        </el-table-column>
        <el-table-column
            prop="ip"
            label="ip"
            width="200">
        </el-table-column>
        <el-table-column
            prop="tel"
            label="手机号"
            width="150">
        </el-table-column>
        <el-table-column
            prop="createDate"
            label="上线时间"
            width="150">
        </el-table-column>
        <el-table-column
            label="操作"
            width="100">
          <template slot-scope="scope">
            <el-button @click="exit(scope.row.id)" type="text" size="small">强退</el-button>
            <el-button type="text" size="small">编辑</el-button>
          </template>
        </el-table-column>

      </el-table>
    </div>


</template>

<script>




export default {
  name: "OnineView",
  data() {
    return {
      //2属性定义
      tableData:[],
      uid:sessionStorage.getItem("uid")
    }
  }, methods: {
    //3自定义方法
    list(){
      this.axios.post("/user/user/useronline").then(res=>{
        if(res.data.code==200){
          this.tableData=res.data.data;
        }
      })
    },
    exit(id){

      if(id==this.uid){
        this.axios.post("/user/user/exit?id="+id).then(res=>{
          if(res.data.code==200){
            this.$message.success(res.data.data);
            this.$router.push("/login")
          }
        })
      }else{
        this.axios.post("/user/user/exit?id="+id).then(res=>{
          if(res.data.code==200){
              this.$message.success(res.data.data);
              this.list();
              location.reload();
          }
        })
      }
    }
  }, created() {
    //4.钩子函数
    this.list();
  },
}
</script>

<style scoped>

</style>